﻿using System.Collections;
using System.Collections.Generic;
using Microsoft.SharePoint;
using SharePoint.Orm.ItemProxy;

namespace SharePoint.Orm.Helpers {
	public class SPListItemConverterEnumerable<T> : IEnumerable<T> {
		private readonly SPListItemCollection _listItems;
		private readonly SPDataContext _context;

		public SPListItemConverterEnumerable(SPDataContext ctx, SPListItemCollection listItems) {
			_context = ctx;
			_listItems = listItems;
		}

		public IEnumerator<T> GetEnumerator() {
			foreach (SPListItem listItem in _listItems) {
				yield return SPListItemProxyGenerator.Create<T>(_context, listItem);
			}
		}

		IEnumerator IEnumerable.GetEnumerator() {
			return GetEnumerator();
		}
	}
}